#ifndef _CSBLIST_H_
#define _CSBLIST_H_

//The idea is to include as much data as possible so that we needn't
//calculate it again every time we draw

#include <buola/utility/uany.h>

namespace buola { namespace gui {

class CSBList;

class CSBItem
{
public:
	CSBItem(CSBList *pData);

//Reference
	CSBList *mList;
	int mIndex;

//Field type
	int mType;
	int mStyle;

//Data
	PIcon mIcon;
	std::wstring mText;
	UAny mValue;

//Geometry
	CPoint_d mPos;				//Absolute
	CSize_d mSize;

	CPoint_d mIconPos;			//Relative

	int mNumLines;
	CPoint_d mTextPos[5];			//Relative
	int mTextWidth[5];
	int mTextLen[5];

	bool mPoints;

//Properties
	bool mSelected;

//Setting values
protected:
	void AddField(int);
	void SetValue(int i,void *v);
	void* GetValue(int i);

public:
	UAny &Value()      {	return mValue;	}

//Sorting
	static int SortAscending(const void*,const void*);
	static int SortDescending(const void*,const void*);

	friend class CSBList;
};

class CSBList
{
public:
	CSBList()
	{
		mSBNextIndex=0x1000000;
	}

	virtual ~CSBList()
	{
	}

	void SBCopy(CSBList*);

protected:
public:
	int GetItemCount()			{	return mSBI.size();	}

//Managing items
	CSBItem *AddItem(const std::wstring&,PIcon,int=-1);
	bool RemoveItem(int);
	void RemoveAllItems();

//Finding and retrieving items
	void SetItemText(int,const std::wstring&);
	std::wstring GetItemText(int);

	CSBItem* GetItem(int);
	CSBItem *FindItem(const std::wstring&);

protected:
//Event notify
	virtual void OnItemAdded(CSBItem*)		{}
	virtual void OnItemChanged(CSBItem*)	{}

	std::vector<CSBItem*> mSBI;

	int mSBNextIndex;

	friend class CSBItem;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
